package com.yls.except.util.RegularHandle;

import java.util.regex.Pattern;

/**
 * 正则验证
 * Created by xs on 2016/7/16.
 */
public class RegularJudge {
    private static final String NUMBERREG = "^([1-9][0-9]*|0)$";
    private static final String CARDREG = "^(\\d{15}$|^\\d{18}$|^\\d{17}(\\d|X|x))$";
    private static final String PHONEREG = "^1[3|4|5|7|8]\\d{9}$";
    private static final String NUMBER = "^([1-9]+(\\.[0-9]{1,2})?|0\\.[1-9][0-9]|0\\.0[1-9])$";
    /**
     * 验证是否为纯数字
     * @param num
     * @return
     */
    public static boolean isnumber(String num) {
        return Pattern.compile(NUMBERREG).matcher(num).find();
    }

    /**
     * 验证是否为身份证号码
     * @param card
     * @return
     */
    public static boolean iscard(String card) {
        return Pattern.compile(CARDREG).matcher(card).find();
    }

    /**
     * 验证是否为手机号
     * @param phone
     * @return
     */
    public static boolean isphone(String phone) {
        return Pattern.compile(PHONEREG).matcher(phone).find();
    }

    /**
     * 验证是否为数字，且最多只能两位小数，且不能为0
     * @param number
     * @return
     */
    public static boolean isnumberreg(String number) {
        return Pattern.compile(NUMBER).matcher(number).find();
    }

    public static void main(String args[]) {
        System.out.println(isnumberreg("123123."));
        System.out.println(isnumberreg("123123.232"));
        System.out.println(isnumberreg("123123.11"));
        System.out.println(isnumberreg("123123.1"));
        System.out.println(isnumberreg("0"));
        System.out.println(isnumberreg("123123"));
    }
}
